//
//  MRHomePageViewController.m
//  MoRan
//
//  Created by MoRan on 2022.
//  Copyright © 2022 MoRan. All rights reserved.
//

#import "MRHomePageViewController.h"

#import "MRSetUpViewController.h" //设置
#import "MRTextTranslationViewController.h" //文本翻译
#import "MRPhoneticTranslationViewController.h" //语音翻译
#import "MRPhotoTranslationViewController.h" //拍照翻译
#import "MRCustomNotificationsViewController.h" //自定义通知
#import "MRTruthDareViewController.h" //真心话大冒险
#import "MRSubscribeViewController.h"

#import "MRHomeFunctionCell.h"

@interface MRHomePageViewController ()

@end

@implementation MRHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.navigationBar.backgroundColor = [UIColor clearColor];
    self.leftItem.hidden = YES;
    [self setRightItemWithIcon:[UIImage imageNamed:@"home_set"] selector:@selector(gotoSetUpViewController)];
    [self.view bringSubviewToFront:self.navigationBar];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MRHomeFunctionCell" bundle:nil] forCellReuseIdentifier:@"MRHomeFunctionCell"];
    
    self.tableView.frame = CGRectMake(0,-self.statusBarHeight, kScreenWidth,kScreenHeight + self.statusBarHeight);
}

- (void)addBackImageView {
    
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;

        subarr = [NSMutableArray arrayWithCapacity:1];
                
        dict =  @{@"class":MRHomeFunctionCell.class,
                  @"height":@([MRHomeFunctionCell getCellFrame:[NSNumber numberWithFloat:kScreenWidth*812/375]]),
                  @"delegate":@YES};
        [subarr addObject:dict];

        [arr addObject:subarr];
        
        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark MRHomeFunctionCellDelegate 文本翻译 语音翻译 拍照翻译 自定义通知 真心话大冒险

- (void)homeFunctionCell:(MRHomeFunctionCell *)cell button:(UIButton *)sender {
    if (!kUserManager.userManager.isSubscribe) {
        [self gotoSubscribeViewController];
        return;
    }
    
    if (sender.tag == 10) {
        //文本翻译
        [self gotoTextTranslationViewController];
    } else if (sender.tag == 11) {
        //语音翻译
        [kMediaManager requestMaikeAuthorizationStatus:^(BOOL granted) {
            if (granted) {
                [self gotoPhoneticTranslationViewController];
            } else {
                [kMediaManager showSetAlertView];
            }
        }];
    } else if (sender.tag == 12) {
        //拍照翻译
        [kMediaManager requestCameraAuthorizationStatus:^(BOOL granted) {
            if (granted) {
                [self gotoPhotoTranslationViewController];
            } else {
                [kMediaManager showAlertViewAboutNotAuthorAccessCamera];
            }
        }];
    } else if (sender.tag == 13) {
        //自定义通知
        [self gotoCustomNotificationsViewController];
    } else if (sender.tag == 14) {
        //真心话大冒险
        [self gotoTruthDareViewController];
    }
}

#pragma mark - goto

//设置
- (void)gotoSetUpViewController {
    MRSetUpViewController* vc = [MRSetUpViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//文本翻译
- (void)gotoTextTranslationViewController {
    MRTextTranslationViewController* vc = [MRTextTranslationViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//语音翻译
- (void)gotoPhoneticTranslationViewController {
    MRPhoneticTranslationViewController* vc = [MRPhoneticTranslationViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//拍照翻译
- (void)gotoPhotoTranslationViewController {
    MRPhotoTranslationViewController* vc = [MRPhotoTranslationViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//自定义通知
- (void)gotoCustomNotificationsViewController {
    MRCustomNotificationsViewController* vc = [MRCustomNotificationsViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//真心话大冒险
- (void)gotoTruthDareViewController {
    MRTruthDareViewController* vc = [MRTruthDareViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
